package com.data.codegenerate.generate.util;

import java.io.UnsupportedEncodingException;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import javax.crypto.Cipher;

public class MachineRsaUtil {
    private static final String a = "YFerfHcGuyXedCm3e8DyBWvoeFCyk1h9Z6wWGOdoZTYQyiFO6H1cYJSHMDE0NBwUpew7GoqwH72m3AqhVm5cbrIbqAlDa2FZh7Qr5t1OlcxbaKMkn+x9Ki4KRzqHVjapXIwaUXQojqZvPN4PoExx3L/26na7cjydBX0iOIAO8mw=";
    private static final String b = "Kq7UG64QROq+0aypnXvWrmJZ24SM3m3hWAKb9cbewrDmAOtkzKEw2eS9kjn+N+5OGsSxOvnN70yuIBBDBReZxUrSUzw0B2DSAjqLK3V/uTqTU1T1tfWjYeNtPcn1+RjgSmdC9YUv0EK8fZOhNJfWUf6j6N1fVXIjkjD/fm/Ww30=";
    private static final String c = "KRwcxkNJy6SohZ08dA47oLbMFqh8AhGhNFyyIBcIqjrqGU3ziTfS8m9mRq9jQEOrFVFQlDGAU/XMxK630FhOk6TgbN93fNH/KWQCl/Ci8WXWmfS3yb/RhJMfZ8g2ODi/vRZbbsWv6VgVn+sLewfN2uJGvHPHRqmdJQKg0eZ0/Gg=";
    private static final String d = "FRX99fEhUaduyArgg7vlJUjzPogerz+FQ8OqSdf5TP3+zQFZIdUPjaK9NmyvGGgTylo4VvM/zjyYZf/635vGcfLs89h49axuyKzlmQ6dIDBXQ03ixlNxVytJEG8jJZzz4OgJzJXyxVpuBHf37uVxNUHyzjfKHHFRzVfGFTw557E=";
    private static final String e = "i9/uJTvvNt5YYj7UQUc2KIYaYsIRTQFgLxIegadXuPfqzOi3HeQjxpGX7YA89DF+B3+VLLHr5mR6Ao9itRbokr0/AwsP9slQKcrrMUnOIMb62GR6SVVRCayyHHRP/gj9CKqKmal5H2e8LEqLj9BtYCNjW07lLuU/3fb1Cnws6Vc=";
    private static final String f = "zm8KOEPvKUF2W3pMbGm32L5xBhqkTFDdAzz0TyN/S1fp4a9Qhb9m/IGVn0tOakqqBFz6G6nT4/uNu78PVgfTJTNdAUvvAfNSjRrEm6SHOHiVUUz8MCa8AGZ319rvytJqEaydnGcPuJuJCJOCiRqGlpYCeul8GUjDnHktYi2WcQdzKU2B2lKjKlRHArIB9Z2HZnqqkhuWSTlAIBPCD7xGYcWUBeHeO3ucEJ4/2TruAN06K+Gk5RxGMkZY24SpIop2Y7483IcyNXJziI251VNGLRdVxakKeg54WwR8S8H2kGc=";

    public static byte[] a(byte[] bArr, byte[] bArr2) {
        try {
            PrivateKey generatePrivate = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(bArr));
            Signature instance = Signature.getInstance("SHA1withRSA");
            instance.initSign(generatePrivate);
            instance.update(bArr2);
            return instance.sign();
        } catch (Exception e2) {
            return null;
        }
    }

    public static boolean a(byte[] bArr, byte[] bArr2, byte[] bArr3) {
        try {
            KeyFactory instance = KeyFactory.getInstance("RSA");
            Signature instance2 = Signature.getInstance("SHA1withRSA");
            instance2.initVerify(instance.generatePublic(new X509EncodedKeySpec(bArr)));
            instance2.update(bArr2);
            return instance2.verify(bArr3);
        } catch (Exception e2) {
            return false;
        }
    }

    public static Object[] a() {
        KeyPair c2 = c();
        if (c2 == null) {
            return null;
        }
        Object[] objArr = new Object[2];
        if (c2 == null) {
            return null;
        }
        byte[] encoded = c2.getPrivate().getEncoded();
        byte[] encoded2 = c2.getPublic().getEncoded();
        objArr[0] = encoded;
        objArr[1] = encoded2;
        return objArr;
    }

    public static String[] b() {
        KeyPair c2 = c();
        if (c2 == null) {
            return null;
        }
        String[] strArr = new String[2];
        if (c2 == null) {
            return null;
        }
        String encodeToString = Base64.getEncoder().encodeToString(c2.getPrivate().getEncoded());
        String encodeToString2 = Base64.getEncoder().encodeToString(c2.getPublic().getEncoded());
        strArr[0] = encodeToString;
        strArr[1] = encodeToString2;
        return strArr;
    }

    public static KeyPair c() {
        long currentTimeMillis = System.currentTimeMillis();
        try {
            KeyPairGenerator instance = KeyPairGenerator.getInstance("RSA");
            SecureRandom instance2 = SecureRandom.getInstance("SHA1PRNG", "SUN");
            instance2.setSeed(currentTimeMillis);
            instance.initialize(1024, instance2);
            return instance.generateKeyPair();
        } catch (Exception e2) {
            return null;
        }
    }

    public static byte[] b(byte[] bArr, byte[] bArr2) {
        try {
            PublicKey generatePublic = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bArr));
            Cipher instance = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            instance.init(1, generatePublic);
            return instance.doFinal(bArr2);
        } catch (Exception e2) {
            return null;
        }
    }

    public static byte[] c(byte[] bArr, byte[] bArr2) {
        try {
            PrivateKey generatePrivate = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(bArr));
            Cipher instance = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            instance.init(2, generatePrivate);
            return instance.doFinal(bArr2);
        } catch (Exception e2) {
            return null;
        }
    }

    public static byte[] d(byte[] bArr, byte[] bArr2) {
        try {
            PKCS8EncodedKeySpec pKCS8EncodedKeySpec = new PKCS8EncodedKeySpec(bArr);
            KeyFactory instance = KeyFactory.getInstance("RSA");
            PrivateKey generatePrivate = instance.generatePrivate(pKCS8EncodedKeySpec);
            Cipher instance2 = Cipher.getInstance(instance.getAlgorithm());
            instance2.init(1, generatePrivate);
            return instance2.doFinal(bArr2);
        } catch (Exception e2) {
            return null;
        }
    }

    public static byte[] a(String str, byte[] bArr) {
        try {
            PKCS8EncodedKeySpec pKCS8EncodedKeySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(str));
            KeyFactory instance = KeyFactory.getInstance("RSA");
            PrivateKey generatePrivate = instance.generatePrivate(pKCS8EncodedKeySpec);
            Cipher instance2 = Cipher.getInstance(instance.getAlgorithm());
            instance2.init(1, generatePrivate);
            return instance2.doFinal(bArr);
        } catch (Exception e2) {
            return null;
        }
    }

    public static byte[] e(byte[] bArr, byte[] bArr2) {
        try {
            KeyFactory instance = KeyFactory.getInstance("RSA");
            PublicKey generatePublic = instance.generatePublic(new X509EncodedKeySpec(bArr));
            Cipher instance2 = Cipher.getInstance(instance.getAlgorithm());
            instance2.init(2, generatePublic);
            return instance2.doFinal(bArr2);
        } catch (Exception e2) {
            return null;
        }
    }

    public static byte[] b(String str, byte[] bArr) {
        try {
            byte[] decode = Base64.getDecoder().decode(str);
            KeyFactory instance = KeyFactory.getInstance("RSA");
            PublicKey generatePublic = instance.generatePublic(new X509EncodedKeySpec(decode));
            Cipher instance2 = Cipher.getInstance(instance.getAlgorithm());
            instance2.init(2, generatePublic);
            return instance2.doFinal(bArr);
        } catch (Exception e2) {
            return null;
        }
    }

    public static byte[] a(String str, String str2) {
        try {
            byte[] decode = Base64.getDecoder().decode(str2);
            byte[] decode2 = Base64.getDecoder().decode(str);
            KeyFactory instance = KeyFactory.getInstance("RSA");
            PublicKey generatePublic = instance.generatePublic(new X509EncodedKeySpec(decode2));
            Cipher instance2 = Cipher.getInstance(instance.getAlgorithm());
            instance2.init(2, generatePublic);
            return instance2.doFinal(decode);
        } catch (Exception e2) {
            return null;
        }
    }

    public static byte[] a(String str) {
        try {
            return MessageDigest.getInstance("SHA").digest(str.getBytes("UTF-8"));
        } catch (Exception e2) {
            return null;
        }
    }

    public static String d() {
        String str;
        try {
            str = new String(a(i(), a), "UTF-8");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
            str = "";
        }
        return str.substring(0, str.indexOf(","));
    }

    public static String e() {
        String str;
        try {
            str = new String(a(i(), b), "UTF-8");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
            str = "";
        }
        return str.substring(0, str.indexOf(","));
    }

    public static String f() {
        String str;
        try {
            str = new String(a(i(), c), "UTF-8");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
            str = "";
        }
        return str.substring(0, str.indexOf(","));
    }

    public static String g() {
        String str;
        try {
            str = new String(a(i(), d), "UTF-8");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
            str = "";
        }
        return str.substring(0, str.indexOf(","));
    }

    public static String h() {
        String str;
        try {
            str = new String(a(i(), e), "UTF-8");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
            str = "";
        }
        return str.substring(0, str.indexOf(","));
    }

    public static String i() {
        try {
            return MachineEncodeUtil.c(f, "136");
        } catch (Exception e2) {
            return null;
        }
    }
}
